package com.fs.dao.Impl;

import com.fs.dao.PaperDao;
import com.fs.pojo.Paper;
import com.fs.utils.JDBCUtils;
import com.fs.vo.QuestionVO;

import java.awt.peer.ListPeer;
import java.util.List;

public class PaperDaoImpl implements PaperDao {

    @Override
    public Paper queryById(String id) {

        String sql = "select * from tb_paper where id = ?";

        List<Paper> papers = JDBCUtils.executeQurey(sql, Paper.class, id);

        return papers == null ? null : papers.get(0);
    }

    @Override
    public List<Paper> queryAll() {
        return null;
    }

    @Override
    public int insert(Paper obj) {
        String sql = "insert into tb_paper (id,teacher_id,paper_name,Instruction,questions,score,updatetime,createtime) values (?,?,?,?,?,?,?,?)";
        return JDBCUtils.executeUpdate(sql,obj);
    }

    @Override
    public int deleteById(String id) {
        String sql = "delete from tb_paper where id = ?";
        return JDBCUtils.executeUpdate(sql,id);
    }

    @Override
    public int update(Paper obj) {
        String sql = JDBCUtils.parseUpdateSQL(obj,"tb_paper");
        return JDBCUtils.executeUpdate(sql,obj);
    }

    @Override
    public List<Paper> queryByTeacherId(String teacherId) {
        String sql = "select * from tb_paper where teacher_id = ?";
        List<Paper> papers = JDBCUtils.executeQurey(sql,Paper.class,teacherId);
        return papers == null ? null :  papers;

    }

    @Override
    public int deleteAll(String id) {
        String sql = "delete from tb_paper where id = ?";
        return JDBCUtils.executeUpdate(sql,id);
    }

}
